package com.ruoyi.common.nmzp;

import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 工作类型对象
 * 是直接写死的数据
 */
@Component
public class JobType implements CommandLineRunner {

    private Map<String, List<JobTypeItem>> jobMap = new HashMap<>();
    private ArrayList<JobTypeItem> jobTypes =  new ArrayList<JobTypeItem>();

    @Override
    public void run(String... args) throws Exception {
        //添加元素
        jobTypes.add(new JobTypeItem().setId(1).setItem("技术").setValue("后端开发"));
        jobTypes.add(new JobTypeItem().setId(2).setItem("技术").setValue("前端开发"));
        jobTypes.add(new JobTypeItem().setId(3).setItem("技术").setValue("Android开发"));
        jobTypes.add(new JobTypeItem().setId(4).setItem("技术").setValue("市场调研"));
        jobTypes.add(new JobTypeItem().setId(5).setItem("市场").setValue("网络营销"));
        jobTypes.add(new JobTypeItem().setId(6).setItem("市场").setValue("活动策划"));
        jobTypes.add(new JobTypeItem().setId(7).setItem("市场").setValue("商务渠道"));
        jobTypes.add(new JobTypeItem().setId(Integer.MAX_VALUE).setItem("其他").setValue("其他"));
        jobMap = jobTypes.stream().collect(Collectors.groupingBy(JobTypeItem::getItem));
    }

    /**
     * 根据ID获取工作类型数据
     * @param id
     * @return
     */
    public JobTypeItem getJobTypeBYId(Integer id) {
        return jobTypes
                .stream()
                .filter(item -> item.getId().equals(id))
                .findFirst()
                .orElse(null);
    }

    public Map<String, List<JobTypeItem>> getJobMap() {
        return jobMap;
    }

    public void setJobMap(Map<String, List<JobTypeItem>> jobMap) {
        this.jobMap = jobMap;
    }

    public ArrayList<JobTypeItem> getJobTypes() {
        return jobTypes;
    }

    public void setJobTypes(ArrayList<JobTypeItem> jobTypes) {
        this.jobTypes = jobTypes;
    }

    public static class JobTypeItem {
        private Integer id;
        private String item;
        private String value;

        public Integer getId() {
            return id;
        }

        public JobTypeItem setId(Integer id) {
            this.id = id;
            return this;
        }

        public String getItem() {
            return item;
        }

        public JobTypeItem setItem(String item) {
            this.item = item;
            return this;
        }

        public String getValue() {
            return value;
        }

        public JobTypeItem setValue(String value) {
            this.value = value;
            return this;
        }
    }
}
